package cn.edu.swu.lyt;

import java.util.Date;
import java.text.SimpleDateFormat;
import java.io.Serializable;

/**
 * 封装单条留言数据的 JavaBean
 */
public class Message implements Serializable {
    private static final long serialVersionUID = 1L;

    private String name;
    private String content;
    private Date timestamp;

    // 用于格式化时间
    private static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

    public Message(String name, String content) {
        this.name = name;
        this.content = content;
        this.timestamp = new Date(); // 自动设置当前时间
    }

    // 无参构造函数（用于序列化）
    public Message() {
    }

    // --- Getter 和 Setter 方法 ---
    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }

    public Date getTimestamp() {
        return timestamp;
    }

    public void setTimestamp(Date timestamp) {
        this.timestamp = timestamp;
    }

    public String getFormattedTimestamp() {
        return DATE_FORMAT.format(timestamp);
    }

    @Override
    public String toString() {
        return "Message{" +
                "name='" + name + '\'' +
                ", content='" + content + '\'' +
                ", timestamp=" + getFormattedTimestamp() +
                '}';
    }
}